<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="com.gzgi.framework.util.*"%>
<%@ page import="com.gzgi.framework.context.*"%>
<%@ page import="com.gzgi.framework.resource.*"%>
<%@ page import="org.jivesoftware.sqlgen.*"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%
      try {  
		    Collection  dataFiles = (Collection) request.getSession().getAttribute(ResourceConstant.RES_SESSION_KEY);
			if(dataFiles == null){
				dataFiles = new HashSet();
			}
            String actionType = request.getParameter("actionType");
			if("upload".equals(actionType)){
				DiskFileUpload fu = new DiskFileUpload();   
				fu.setSizeMax(102400000); 
				fu.setSizeThreshold(8192); 
				fu.setRepositoryPath(ApplicationContext.getAppPath()+ "/WEB-INF/temp/"); // 设置临时目录   
				List fileItems = fu.parseRequest(request);  
				Iterator iter = fileItems.iterator();   
				 while (iter.hasNext()) {   
					FileItem fileItem = (FileItem) iter.next();   
					String filename = fileItem.getName();// 获得文件名，这个文件名包括路径：   
					if (filename != null) {   
						// 在这里可以记录用户和文件信息   
						if(filename.indexOf("/") != -1){
							filename = filename.substring(filename.lastIndexOf("/")+1, filename.length());
						} else if(filename.indexOf("\\") != -1){
							filename = filename.substring(filename.lastIndexOf("\\")+1, filename.length());
						}

						SQLGen sqlGen = new SQLGen();
						sqlGen.addInputStream(fileItem.getInputStream());
						Connection con = ContextFactory.getConnection();
						String sql = sqlGen.generateSQL(con);
						System.out.println(sql);

					}   
				}   
				request.getSession().setAttribute(ResourceConstant.RES_SESSION_KEY, dataFiles);
				response.setContentType("text/html;charset=UTF-8");   
				response.getWriter().print("{'success':true,'message':'上传成功'}");   
			}  
         } catch (Exception ex) {   
            ex.printStackTrace();   
            response.getWriter().print("{'success':flase,'message':'失败'}");   
         }   
%>